//
//  InviteViewController.m
//  Cat
//
//  Created by lushitong on 2018/12/1.
//  Copyright © 2018年 lushitong. All rights reserved.
//

#import "InviteViewController.h"
#import "QKShareLiveSheetManager.h"
#import "ShareView.h"
#import "FMDBUser.h"
#import "UserInfoManager.h"

@interface InviteViewController ()

@property (nonatomic, strong) UIImageView *shareImageView;
@property (nonatomic, strong) UILabel *shareLabel;
@property (nonatomic, strong) UIButton *shareButton;
@property (nonatomic, strong) ShareView *shareView;
@property (nonatomic, strong) UIImageView *infoView;


@end

@implementation InviteViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    [self.topTitleView setDetailDic:@{Nav_Title:@"邀请好友"}.mutableCopy];
	[self loadAllSubViews];
	[self setShareInfo];
}

- (void)setShareInfo {
	FMDBUser *user = [UserInfoManager userWithPhone:UDPhone];
	self.shareLabel.text = [NSString stringWithFormat:@"我的专属邀请码:%@",user.inviteCode];
}

- (void)quickInvite {
	[QKShareLiveSheetManager showPlayListWithSuperView:self.view customView:self.shareView];
}

- (void)loadAllSubViews {
	
	[self.view addSubviews:@[self.shareImageView,self.infoView,self.shareLabel,self.shareButton]];
	[self.shareImageView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.right.bottom.equalTo(self.view);
		make.top.equalTo(self.topTitleView.mas_bottom);
	}];
	
	[self.shareButton mas_makeConstraints:^(MASConstraintMaker *make) {
		make.height.equalTo(@(kQKFitModuleDecimal(50))).priorityHigh();
		make.bottom.equalTo(self.view.bottom).offset(-kQKFitModuleDecimal(20.0));
		make.left.equalTo(self.view.mas_left).offset(kQKFitModuleDecimal(30));
		make.right.equalTo(self.view.mas_right).offset(-kQKFitModuleDecimal(30));
	}];
	
	[self.infoView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.size.equalTo(CGSizeMake(ScreenWidth - kQKFitModuleDecimal(90), kQKFitModuleDecimal(300)));
		make.centerY.equalTo(self.shareImageView.mas_centerY).offset(kQKFitModuleDecimal(20));
		make.centerX.equalTo(self.shareImageView.mas_centerX);
	}];
	
	[self.shareLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerX.equalTo(self.shareButton.mas_centerX);
		make.bottom.equalTo(self.shareButton.mas_top).offset(-kQKFitModuleDecimal(20));
	}];
}

#pragma mark----- lazy init -----

- (UIButton *)shareButton {
	if (!_shareButton) {
		_shareButton = [UIButton buttonWithTitle:@"立即邀请" color:[UIColor whiteColor] font:[UIFont boldSystemFontOfSize:kQKFitFont(16)]];
		[_shareButton setBackgroundImage:[UIImage imageWithColor:COLOR_WITH_HEX(0xFF3F3F)] forState:UIControlStateNormal];
		_shareButton.layer.cornerRadius = kQKFitModuleDecimal(6.0);
		_shareButton.layer.masksToBounds = YES;
		[_shareButton addTarget:self action:@selector(quickInvite) forControlEvents:UIControlEventTouchUpInside];
	}
	return _shareButton;
}

- (ShareView *)shareView {
	if (!_shareView) {
		_shareView = [[ShareView alloc] initWithFrame:CGRectMake(0.0, 0.0, ScreenWidth, kQKFitModuleDecimal(172))];
	}
	return _shareView;
}

- (UIImageView *)shareImageView {
	if (!_shareImageView) {
		_shareImageView = [[UIImageView alloc] init];
		_shareImageView.image = [UIImage imageNamed:@"maio_back_pic"];
		_shareImageView.contentMode = UIViewContentModeScaleAspectFill;
		_shareImageView.layer.masksToBounds = YES;
	}
	return _shareImageView;
}

- (UILabel *)shareLabel {
	if (!_shareLabel) {
		_shareLabel = [UILabel labelWithText:@"我的专属邀请码:9923467" font:[UIFont systemFontOfSize:kQKFitFont(18)] textColor:COLOR_WITH_HEX(0x4C4947)];
	}
	return _shareLabel;
}

- (UIImageView *)infoView {
	if (!_infoView) {
		_infoView = [[UIImageView alloc] init];
		_infoView.image = [UIImage imageNamed:@"info"];
	}
	return _infoView;
}
@end
